﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebApplication5.Controller;
using WebApplication5.Model;

namespace WebApplication5.Pages
{
    public partial class ShowAll : System.Web.UI.Page
     
    {
        protected personCtr perCtr = new personCtr();
        protected projectCtr pCtr = new projectCtr();
        protected userstoriesCtr uCtr = new userstoriesCtr();
        protected taskCtr tCtr = new taskCtr();

  
        protected void Page_Load(object sender, EventArgs e)
        {
            Site1 s = Page.Master as Site1;
            s.SelectedMenu = "ShowAll";


        }
        protected void Page_Init(object sender, EventArgs e)
        {
            List<WebApplication5.Model.Login> pa = perCtr.GetAllEmployee();
            var datasource = from p in pa
                             select new
                             {
                                 p.id,
                                 p.companyId,
                                 p.firstName,
                                 p.lastName,
                                 p.password,
                                 p.phoneNumber,
                                 p.Project,
                                 p.userName,
                                 p.verfied,
                                 DisplayField = String.Format("{0} {1}", p.firstName, p.lastName)
                             };

            ListBoxEmployee.DataSource = datasource;
            ListBoxEmployee.DataValueField = "id";
            ListBoxEmployee.DataTextField = "DisplayField";
            ListBoxEmployee.DataBind();
        }

        protected void ListBoxEmployee_SelectedIndexChanged(object sender, EventArgs e)
        {

            int id = 0;
            var input = ListBoxEmployee.SelectedValue;

            
            try
            {
              id = int.Parse(input);
            }
            catch (FormatException error)
            {

            }

            List<WebApplication5.Model.Login> lo = perCtr.GetAllEmployee(id);
            var dataPr = from l in lo
                         select new
                         {
                             l.id,
                             l.firstName,
                             l.lastName,
                             l.userName,
                             l.password,
                             l.phoneNumber,
                             l.verfied,
                             l.companyId,
                             l.Project
                         };

            List<Project> pr = pCtr.GetAllProjectId(id);
      
            var dataSo = from s in pr
                             select new
                             {
                                 s.id,
                                 s.cost,
                                 s.endDate,
                                 s.Login,
                                 s.loginId,
                                 s.name,
                                 s.startDate,
                                 s.status,
                                 s.time,
                                 s.Userstory,
                                 DisplayField = String.Format("{0}", s.name)
                             };

                ListBoxProject.DataSource = dataSo;
                ListBoxProject.DataValueField = "id";
                ListBoxProject.DataTextField = "DisplayField";
                ListBoxProject.DataBind();

                GridView1.DataSource = dataPr;
                GridView1.DataBind();

            
        }

        protected void ListBoxProject_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = 0;
            var input = ListBoxProject.SelectedValue;


            try
            {
                id = int.Parse(input);
            }
            catch (FormatException error)
            {

            }

            List<Project> pr = pCtr.GetAllProjectIdsame(id);
            var datapro = from p in pr
                          select new
                          {
                              p.id,
                              p.name,
                              p.cost,
                              p.startDate,
                              p.endDate,
                              p.loginId,
                              p.status,
                              p.time,
                              p.Userstory,
                          };

            List<Userstory> ur = uCtr.GetAllUserstoryId(id);

            var data = from s in ur
                         select new
                         {
                             s.id,
                             s.actual,
                             s.asA,
                             s.Estimate,
                             s.iWantTo,
                             s.name,
                             s.priority,
                             s.Project,
                             s.projectId,
                             s.soThat,
                             s.Task,
                             DisplayField = String.Format("{0}", s.name)
                         };

            ListBoxUserStories.DataSource = data;
            ListBoxUserStories.DataValueField = "id";
            ListBoxUserStories.DataTextField = "DisplayField";
            ListBoxUserStories.DataBind();

            GridView1.DataSource = datapro;
            GridView1.DataBind();
        }


        protected void ListBoxUserStories_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = 0;
            var input = ListBoxUserStories.SelectedValue;


            try
            {
                id = int.Parse(input);
            }
            catch (FormatException error)
            {

            }

            List<Userstory> up = uCtr.GetAllUserstoryIdSame(id);
            var dataU = from u in up
                        select new
                        {
                            u.name,
                            u.id,
                            u.asA,
                            u.iWantTo,
                            u.soThat,
                            u.Estimate,
                            u.actual,
                            u.priority,
                            u.projectId,
                            u.Project,
                            u.Task,
                            
                        };

            List<Task> ur = tCtr.GetAllTaskId(id);

            var data = from st in ur
                       select new
                       {
                           st.id,
                           st.name,
                           st.status,
                           st.type,
                           st.Userstory,
                           st.userstoryId,
                         

                           DisplayField = String.Format("{0}", st.name)
                       };

            ListBoxTask.DataSource = data;
            ListBoxTask.DataValueField = "id";
            ListBoxTask.DataTextField = "DisplayField";
            ListBoxTask.DataBind();

            GridView1.DataSource = dataU;
            GridView1.DataBind();
            
        }

        protected void ListBoxTask_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = 0;
            var input = ListBoxUserStories.SelectedValue;


            try
            {
                id = int.Parse(input);
            }
            catch (FormatException error)
            {

            }


            List<Task> ur = tCtr.GetAllTaskIdSame(id);

            var data = from st in ur
                       select new
                       {
                           st.id,
                           st.name,
                           st.status,
                           st.type,
                           st.Userstory,
                           st.userstoryId,

                       };

            GridView1.DataSource = data;
            GridView1.DataBind();
            
        }
        



        

    }
}